#include"kernel/types.h"
#include"kernel/stat.h"
#include"user/user.h"
int main(int argc, const char *argv[]){
    int pid, fpid,spid;
    int r,w;
    char r_buf[0x200],w_buf[0x200]="pingpong";
    static int pfd[2];

    pipe(pfd);
    pid=fork();
    if(pid==0){
        spid=getpid();
        close(pfd[1]);
        r=read(pfd[0],r_buf,sizeof(r_buf));
        printf("Child\tPID:%d\t%d bytes read\t%s\n",spid,r,r_buf);
        close(pfd[0]);
        exit(0);
    }else if(pid>0){
        fpid=getpid();
        close(pfd[0]);
        w=write(pfd[1],w_buf,sizeof(w_buf));
        wait(0);
        printf("Parent\tPID:%d\t%d bytes read\t%s\n",fpid,w,w_buf);
        close(pfd[1]);
        exit(0);
    }else{
        printf("fork error");
        exit(1);
    }
}